package com.im.chat.service.impl;

import com.im.chat.base.BasePageServiceImpl;
import com.im.chat.dao.ChatSessionMapper;
import com.im.chat.model.ChatSession;
import com.im.chat.service.ChatSessionService;
import com.im.chat.util.ChatConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ChatSessionServiceImpl extends BasePageServiceImpl<ChatSessionMapper, ChatSession> implements ChatSessionService {
    @Autowired
    private ChatSessionMapper chatSessionMapper;

    @Override
    protected void initMapper() {
        this.mapper = chatSessionMapper;
    }


    @Override
    public ChatSession getChatSessionByChatId(long chatId) {
        return mapper.getChatSessionByChatId(chatId);
    }

    @Override
    public ChatSession getChatSessionByMemberIdAndAdminId(long memberId,long adminId) {
        return mapper.getChatSessionByMemberIdAndAdminId(memberId,adminId);
    }

    @Override
    public long insertChatSession(ChatSession chatSession) {
        return mapper.insertChatSession(chatSession);
    }

    @Override
    public List<ChatSession> selectByAdmin(long adminId) {
        Map<String,Object> map = new HashMap<>();
        map.put("isDel", ChatConstant.IS_DEL_N);
        map.put("status", ChatConstant.CHAT_SESSION_STATUS_NORMAL);
        map.put("sortParamString","is_top desc,top_time desc,update_time desc");
        map.put("adminId",adminId);
        return chatSessionMapper.selectByMap(map);
    }


    @Override
    public List<ChatSession> selectAllMemberByAdmin(Long adminId) {
        return chatSessionMapper.selectAllMemberByAdmin(adminId);
    }

    @Override
    public List<ChatSession> selectByMember(long memberId) {
        Map<String,Object> map = new HashMap<>();
        map.put("isDel", ChatConstant.IS_DEL_N);
        map.put("status", ChatConstant.CHAT_SESSION_STATUS_NORMAL);
        map.put("sortParamString","is_top desc,top_time desc,update_time desc");
        map.put("memberId",memberId);
        return chatSessionMapper.selectByMap(map);
    }

    @Override
    public int adminTopSession(long chatId, long adminId) {
        return chatSessionMapper.adminTopSession(chatId,adminId);
    }

    //TODO:待修复？？？？
    @Override
    public int updateAdminSession(long chatId, long adminId) {
        ChatSession chatSession = new ChatSession();
        chatSession.setId(chatId);
        chatSession.setAdminId(adminId);
        return chatSessionMapper.updateByPrimaryKeySelective(chatSession);
    }

    @Override
    public int adminCloseSession(long chatId, long adminId) {
        return chatSessionMapper.adminCloseSession(chatId,adminId);
    }

    @Override
    public int blackSession(long chatId, long adminId) {
        return chatSessionMapper.blackSession(chatId,adminId);
    }






}
